import yaml
from PyQt5.QtWidgets import (
    QDialog, QVBoxLayout, QHBoxLayout, QFormLayout,
    QLabel, QLineEdit, QPushButton, QTextEdit, QWidget,
    QSpinBox, QDoubleSpinBox, QComboBox, QDialogButtonBox
)

from PyQt5.QtCore import Qt

class ModelParamsDialog(QDialog):
    def __init__(self, parent=None, default_params=None):
        super().__init__(parent)
        self.setWindowTitle("模型参数设置")
        self.params = default_params or {
            "confidence": "0.25",
            "iou": "0.45",
            "device": "cpu",
            "imgsz": "640"
        }

        layout = QFormLayout(self)

        self.conf_edit = QLineEdit(self.params["confidence"])
        self.iou_edit = QLineEdit(self.params["iou"])
        self.device_edit = QLineEdit(self.params["device"])
        self.imgsz_edit = QLineEdit(self.params["imgsz"])

        layout.addRow("置信度阈值 (Confidence)", self.conf_edit)
        layout.addRow("IOU 阈值 (NMS)", self.iou_edit)
        layout.addRow("检测设备 (CPU/GPU)", self.device_edit)
        layout.addRow("输入尺寸 (Image Size)", self.imgsz_edit)

        buttons = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
        buttons.accepted.connect(self.accept)
        buttons.rejected.connect(self.reject)
        layout.addWidget(buttons)

    def get_params(self):
        return {
            "confidence": self.conf_edit.text(),
            "iou": self.iou_edit.text(),
            "device": self.device_edit.text(),
            "imgsz": self.imgsz_edit.text()
        }
